package ${packageInfo.packageName}.controller;

import ${packageInfo.packageName}.entity.${packageInfo.className};
import ${packageInfo.packageName}.service.${packageInfo.className}Service;
import com.yangle.frame.common.controller.BaseController;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import tk.mybatis.mapper.util.StringUtil;
import java.util.UUID;

/**
 * Created by yangle on 2018/5/26.
 */
@Controller
@RequestMapping("/${packageInfo.modelName}/${(packageInfo.className)?lower_case}")
public class ${packageInfo.className}Controller extends BaseController<${packageInfo.className}>{
    @Autowired
    private ${packageInfo.className}Service ${(packageInfo.className)?uncap_first}Service;
    @RequestMapping("/list")
    public String list(HttpServletRequest request, ${packageInfo.className} entity) {
        super.list(request, entity, ${(packageInfo.className)?uncap_first}Service);
        return "${packageInfo.modelName}/${(packageInfo.className)?lower_case}/list";
    }

    @RequestMapping("/edit")
    public String edit(HttpServletRequest request) {
        super.edit(request, ${(packageInfo.className)?uncap_first}Service);
        return "${packageInfo.modelName}/${(packageInfo.className)?lower_case}/edit";
    }

    @RequestMapping("/save")
    public String save(HttpServletRequest request, ${packageInfo.className} entity) {
        if (StringUtil.isNotEmpty(entity.getId())) {
            super.update(request, entity, ${(packageInfo.className)?uncap_first}Service);
        } else {
            entity.setId(UUID.randomUUID().toString());
            super.create(request, entity, ${(packageInfo.className)?uncap_first}Service);
        }
        return "common/result";
    }

    @RequestMapping("/delete")
    public String delete(HttpServletRequest request) {
        super.delete(request, ${(packageInfo.className)?uncap_first}Service);
        return "common/result";
    }

    @RequestMapping("/view")
    public String view(HttpServletRequest request) {
        super.view(request, ${(packageInfo.className)?uncap_first}Service);
        return "${packageInfo.modelName}/${(packageInfo.className)?lower_case}/view";
    }
}